<%@page import="java.util.UUID"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/pages/common/taglib.jsp" %>
<%
    String gridId = UUID.randomUUID().toString();
    request.setAttribute("gridId", gridId);
%>
<script type="text/javascript">

    $(function () {
        var gridId = '${gridId}';
        var roleGrid = $("#" + gridId + "_roleGrid");
        var roleForm = $("#" + gridId + "_roleForm");

        roleForm.find(".searchBt").click(function () {
            var roleName = roleForm.find("input[name='search.role.roleName']").val();
            var roleKey = roleForm.find("input[name='search.role.roleKey']").val();

            roleGrid.datagrid("load", {roleName: roleName, roleKey: roleKey});
        });

        roleGrid = roleGrid.datagrid({
            url: ctx + "/roleAction/queryRoles.do",
            columns: [[
                    {field: 'id', checkbox: true},
                    {title: '角色名称', field: 'roleName', align: 'left', width: 120},
                    {title: '标识', field: 'roleKey', align: 'left', width: 300},
                    {title: '默认', field: 'isDefault', align: 'left', width: 80, formatter: function (rowdata, index, value) {
                            if (value == 1) {
                                return "是";
                            } else {
                                return "";
                            }
                        }}
                ]],
            fit: true,
            pagination: true,
            border: false,
            singleSelect: true,
            checkbox: true,
            selectOnCheck: false,
            checkOnSelect: false,
            pageSize: 30,
            toolbar: [
                {text: "选择", iconCls: 'icon-add', handler: function (items) {
                        var rows = roleGrid.datagrid("getChecked");
                        if (!rows || rows.length <= 0) {
                            alert("请选择数据");
                        } else {
                            var selected = [];
                            $.each(rows, function (i, row) {
                                selected.push(row.id);
                            });
                            top.webUtils.topicPublish("userRole.select.success", selected);
                        }
                    }}
            ]
        });
    });

</script>
<div id="${gridId}_roleGrid">

</div>